SG Window Window Object
Message Event

©1998 by Stinga

Properties     Methods      Constants     Error Codes
Description

Fired when enabled message is received by attached window.

Syntax

Private Sub window_Message(ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByRef result As Long)

Part Description
window Expression that evaluates to Window object
msg Received message code.
wParam Message specific data
lParam Message specific data
result Message result code
Remarks

Message event occurs when one of the enabled messages is received by the attached window.

Values and interpretation of wParam and lParam parameters depends on received message. Please consult Win32 API documentation for more details on parameters passed with different messages.

If message is not handled in the event procedure, you must call CallWindowProc method and let default window procedure handle message. How and when you are going to call it depends on what you want to accomplish. In some cases you will handle message entirely in the VB code and you will not call default window procedure at all.

Result is window procedure return value. You must update value of the result parameter according to the received message. Win32 API documentation contains info about these return values.

Be aware that you should avoid putting breakpoints into the message event handler. You can use Debug.Print statement to find out what is happening inside message handler.

Example
Const PBT_APMQUERYSUSPEND  = 0
Const BROADCAST_QUERY_DENY = &H424D5144&

Private WithEvents mWnd As SGWindow.Window

Private Sub Form_OnLoad()
   Set mWnd = New SGWindow.Window
   mWnd.hWnd = Me.hWnd
   mWnd.EnableMessage wm_POWERBROADCAST
   mWnd.Hooked = True
End Sub
Private Sub mWnd_Message(ByVal msg As Long, _
            ByVal wParam As Long, ByVal lParam As Long, _
            ByRef result As Long)

   If wParam = PBT_APMQUERYSUSPEND Then
      ' Deny suspend mode
      result = BROADCAST_QUERY_DENY
   Else
      ' Default message processing
      result = mWnd.CallWindowProc(msg, wParam, lParam)
   End If
End Sub